import { Injectable } from '@nestjs/common';
import type { Express } from 'express'
import { RESPONSE_CODE } from "@/enums/code";
import { saveFiles } from "@/utils/dir";
import type { FileType, FilesType } from './sysFile.dto'

@Injectable()
export class SysFileService {

  /**
  * 上传
  * @param ctx
  * @method post
  */
  async upload(file: FileType | FilesType) {
    try {
      const filesList = Object.values(file).flat();
      const res = await saveFiles(filesList);

      return {
        code: RESPONSE_CODE.SUCCESS,
        data: res.length > 1 ? res : res[0],
        msg: null,
      };
    } catch (error: any) {
      return {
        code: RESPONSE_CODE.ERROR,
        data: null,
        msg: error.message,
      };
    }
  }
}
